import java.util.HashSet;
import java.util.Set;

/**
 * @author 挚爱之夕
 * @date 2021/9/12 - 09 - 12 - 19:47
 * @Description: PACKAGE_NAME
 * @Version: 1.0
 */
public class MusicList  {
    Set<Music> songList = new HashSet<>();
    //初始化
    private void init(){
        songList.add(new Music("逆战","张杰",120));
        songList.add(new Music("爱不会绝迹","林俊杰",180));
    }
    //构造方法
    public MusicList() {
        this.init();
    }
    //打印歌单
    public void printMusicSet(){
        int current = 1;
        for (Music music:songList
             ) {
            System.out.printf("第%d首歌曲：",current++);
            System.out.println(music);
        }
    }
    //添加歌曲
    public void addMusic(Music music){
        songList.add(music);
    }
    //删除歌曲:根据歌曲名
    public Music deleteMusic(String name) throws IllegalArgumentException{
        for (Music music:songList
             ) {
            if(music.getName().equals(name)){
                boolean isDelete=songList.remove(music);
                return music;
            }
        }
        throw new IllegalArgumentException("操作有误！该歌曲不存在！");
    }
    //查询歌曲:根据歌名
    public Music findMusic(String name) throws IllegalArgumentException{
        for (Music music:songList
             ) {
            if(music.getName().equals(name)){
                return music;
            }
        }
        throw new IllegalArgumentException("该歌曲不存在！");
    }
    //统计歌单中歌曲总数
    public int total(){
        return songList.size();
    }
}
